package kku.cs.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import org.newdawn.slick.util.ResourceLocation;

public class HTTPLocation implements ResourceLocation {

	@Override
	public InputStream getResourceAsStream(String ref) {
		try {
			URL u = getResource(ref);
			if(u==null)return null;
			return u.openConnection().getInputStream();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public URL getResource(String ref) {
		if(ref.startsWith("http://")){
		  try {
			return new URL(ref);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		}
		return null;
	}

}
